﻿@model OrderMasterModel

@{
    ViewBag.Title = "订单退款";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@{
    var viewModel = Model ?? new OrderMasterModel();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
    Dictionary<string, string> labelDicTypeName = ReleaseBiz.GetLabelTypeNameDic();
}
<form id="S_Form" action="@Url.Action("refund", "OrderMaster")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" style="width:50%">
                <h5>
                    销售订单详情
                </h5>
                <input type="hidden" value="@viewModel.view_Order.order_id" name="order_id" />
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">订单号</td>
            <td>
                @viewModel.view_Order.order_NO
            </td>

            <td class="tableleft">下单用户</td>
            <td>
                <div>手机号：@viewModel.view_Order.account_mobile</div>
                <div>会员名称：@viewModel.view_Order.member_name</div>
                <div>代购编号：@viewModel.view_Order.replace_buyer_NO</div>
            </td>
        </tr>
        <tr>
            <td class="tableleft">订单金额</td>
            <td>
                @viewModel.view_Order.total_money
            </td>
            <td class="tableleft">订单状态</td>
            <td>
                @(MyEnumHelper.GetEnumItemDescription<OrderStatus>(viewModel.view_Order.order_status.Value))
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">下单时间</td>
            <td>@viewModel.view_Order.create_time.ToString(1)</td>

            <td width="10%" class="tableleft">支付信息</td>
            <td>
                <div>
                    支付方式：@(MyEnumHelper.GetEnumItemDescription<PayType>(viewModel.view_Order.pay_type.Value))
                </div>
                @if (viewModel.view_Order.is_succ.Value == (int)PaySucc.Paid)
                {
                    <div class="green">已支付 支付时间：@viewModel.view_Order.pay_succ_time.ToString(1)</div>

                    if (viewModel.view_Order.pay_type.Value == (int)PayType.UnderLine)
                    {
                        Html.RenderPartial(Url.Content("~/Views/Common/ImgsOne.cshtml"), viewModel.view_Order);
                    }
                }
                @if (viewModel.view_Order.is_succ.Value == (int)PaySucc.NotPay)
                {
                    <span class="red">
                        未支付
                        @if (viewModel.view_Order.order_status.Value == (int)OrderStatus.Cancel)
                        {
                            <span>支付已关闭</span>
                        }
                        else if (viewModel.view_Order.order_status.Value == (int)OrderStatus.WaitPay)
                        {
                            if (viewModel.view_Order.pay_end_time.HasValue)
                            {
                                <span>支付关闭时间：@viewModel.view_Order.pay_end_time.ToString(1)</span>
                            }
                        }
                    </span>
                }
            </td>
        </tr>
        <tr>
            <td class="tableleft">发货状态<em></em></td>
            <td>
                @{
                    switch (viewModel.view_Order.is_send.Value)
                    {
                        case (int)IsSend.NotSend:
                            <div class="red">
                                @(MyEnumHelper.GetEnumItemDescription<IsSend>(viewModel.view_Order.is_send.Value))
                            </div>
                            break;
                        case (int)IsSend.Sended:
                            @:<div class="green">@(MyEnumHelper.GetEnumItemDescription<IsSend>(viewModel.view_Order.is_send.Value)) 发货时间：@viewModel.view_Order.send_time.ToString(1)</div>
                            break;
                    }
                }
            </td>
            <td class="tableleft">发票信息<em></em></td>
            <td>
                @switch (viewModel.view_Order.is_invoice.Value)
                {
                    case 0:
                        @:<div>不需要发票</div>
                        break;
                    case 1:
                        if (viewModel.aDZ_OrderInvoiceRel == null)
                        {
                            <div class="red">发票资料还未上传</div>
                        }
                        else
                        {
                            <div>
                                <div class="thumb-item-wrap">
                                    <a href="javacript:void(0);" class="img-wrap">
                                        <img class="thumb-img" src="@ImageFileBiz.GetImg(viewModel.aDZ_OrderInvoiceRel.invoice_img, "small")" style="width: 100px;margin:auto;">
                                    </a>
                                </div>
                            </div>

                            if (viewModel.aDZ_OrderInvoiceRel.is_ready == 1)
                            {
                                <div class="green">发票已开 开票时间：@viewModel.aDZ_OrderInvoiceRel.invoice_date.ToString(1)</div>
                            }
                        }
                        break;
                }
            </td>
        </tr>
        <tr>
            <td colspan="4" style="width:50%">
                <h5>
                    商品信息
                </h5>
            </td>
        </tr>
        <tr>
            <td colspan="4" style="width:100%">
                <table class="table table-bordered table-hover definewidth m10">
                    <thead>
                        <tr>
                            <th style="width:40px"><input type="checkbox" name="chkall" id="chkall" />全选</th>
                            <th style="width:70px">图片</th>
                            <th>料号</th>
                            <th>品牌</th>
                            <th>分类</th>
                            <th>供应商</th>
                            <th>板块</th>
                            <th>库存价格</th>
                            <th>订购数量</th>
                            <th>单位</th>
                            <th>供货单价</th>
                            <th>佣金比例</th>
                            <th>销售单价</th>
                            <th>订单总价</th>
                            <th>币种</th>
                            <th>佣金金额</th>
                            <th></th>
                        </tr>
                    </thead>
                    @if (viewModel.orderGoods != null && viewModel.orderGoods.Count != 0)
                    {
                        int index = 0;
                        foreach (var orderGoods in viewModel.orderGoods)
                        {
                            var m = orderGoods.views_Goods;
                            var goodsdetail = orderGoods.aDZ_OrderDetails;
                            index++;
                <tr class="@HtmlPagerHelper.TrClass(index)">
                    <td><input type="checkbox" name="cbx_last" value="@m.goods_id" />@m.goods_id</td>
                    <td>
                        @{
                            var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id);
                            foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
                            {
                                <a href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
                            }
                        }
                    </td>
                    <td>@m.MPN</td>
                    <td>@m.brand_name</td>
                    <td>@m.category_name</td>
                    <td>@m.supplier_name</td>
                    <td>
                        <div>@labelDicTypeName[m.label_type.ToString()]</div>
                    </td>
                    <td>@m.price</td>
                    <td>@goodsdetail.amount</td>
                    <td>@m.goods_unit</td>

                    <td>@(m.supply_price == null ? "-" : m.supply_price.Value.ToString("f5"))</td>
                    <td>@(m.supply_price == null ? "-" : ((goodsdetail.sell_price - m.supply_price) / goodsdetail.sell_price).Value.ToString("f5"))</td>

                    <td>@((goodsdetail.sell_price).ToString("f5"))</td>

                    <td><input type="text" name="total_money" id="gid_@m.goods_id" value="@goodsdetail.total_money.Value.ToString("f2")" /></td>
                    <td>
                        @switch (m.currency_type)
                        {
                            case 0:
                                @:<div class="">人民币</div>
                                break;
                            case 1:
                                @:<div class="red">美金</div>
                                break;
                        }
                    </td>
                    <td>@(m.supply_price == null ? "-" : ((goodsdetail.sell_price - m.supply_price) * goodsdetail.amount).Value.ToString("f5"))</td>
                    <td>
                        <a href="@Url.Action("detailInfo", "product", new { id = m.goods_id})">查看</a>
                    </td>
                </tr>
                                            }
                                        }
                </table>
            </td>
        </tr>
        <tr>
            <td class="tableleft">退款原因<em></em></td>
            <td><textarea id="reason" name="reason" style="width:80%;" maxlength="2500" placeholder="用户未填备注" cols="4"></textarea></td>
        </tr>
        <tr>
            <td colspan="4" style="width:50%">
                <button type="button" class="btn btn-primary" onclick="refund()">退款申请</button> &nbsp;&nbsp;
                <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
            </td>
        </tr>
    </table>
</form>
<script>
    var cancelButton =
        {
            text: '取消',
            elCls: 'button',
            handler: function () {
                this.close();
            }
        };

    function refund() {
        var order_id = "@viewModel.view_Order.order_id";
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择要退款的商品", 'warning');
            return;
        }

        var reason = $("#reason").val();
        if (reason == "") {
            BUI.Message.Alert("请输入退款原因", 'warning');
            return;
        }

        var t = "1";
        var moneys = "";
		
		$.each(ids.split(","),function(index,item){
			if(!item) return ;
			var money = $("#gid_"+item).val();
            if (money == "" || money == 0) {
                t="0"
                return false;
            }
            moneys += money + ',';
        });
        if (t == "0") {
            BUI.Message.Alert("请输入退款商品的订单总价", 'warning');
            return false;
        }

        if (moneys.length == 0) {
            BUI.Message.Alert("请选择要退款的商品1", 'warning');
            return;
        }

        BUI.Message.Show({
            title: '提示',
            msg: '本次退款总金额：' + moneys+' 确定要将选择的商品都退款吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("Refund", "ordermaster")";
                      parameter = {
                        order_id: order_id,
                        good_ids: ids,
                        moneys: moneys,
                        reason: reason
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, function () { self.location = document.referrer; });
                      });
                      this.close();
                  }
              },
                cancelButton

            ]
        });
    }
</script>
